﻿/* This Component Library is licensed under the GNU General Public License version 2 (GPLv2) 
 * You can use this software and its associated files as you wish so long as derived versions
 * or works based on this library are also freely released.
 * If you require a commercial licence for this software without the above restrictions please
 * contact me via scott_blood@hotmail.com or via CodePlex.
 * (c) 2010 Scott Blood
 * Visit SGBControls.CodePlex.com for the latest version of this library.
 */ 
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace SGBControls.Editors
{
    class SGBBaseTextBox : TextBox
    {
        private const int WM_PASTE = 0x0302;
        private const int WM_CUT = 0x0300;
        private const int WM_COPY = 0x0301;

        public event ClipboardOperationEventHandler ClipboardOperation;

        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_PASTE:
                    {
                        if (ClipboardOperation != null)
                            ClipboardOperation(this, new ClipboardOperationArgs(ClipboardOperationType.Paste));
                        break;
                    }
                case WM_COPY:
                    {
                        if (ClipboardOperation != null)
                            ClipboardOperation(this, new ClipboardOperationArgs(ClipboardOperationType.Copy));
                        break;
                    }
                case WM_CUT:
                    {
                        if (ClipboardOperation != null)
                            ClipboardOperation(this, new ClipboardOperationArgs(ClipboardOperationType.Cut));
                        break;
                    }
            }
                        
            base.WndProc(ref m);
        }

        public TextBox GetNativeControl()
        {
            return this as TextBox;
        }
    }
}
